//
//  YRMainViewController.swift
//  新浪微博
//
//  Created by Viper on 16/6/24.
//  Copyright © 2016年 Viper. All rights reserved.
//

import UIKit

class YRMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad() 

        let maintabBar = YRMainTabBar()
        
        setValue(maintabBar, forKey: "tabBar")
        
        //设置代理
        maintabBar.YRDelegate = self
        
        addChildViewController(YRHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(YRMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(YRDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(YRProfileTableViewController(), imageName: "tabbar_profile", title: "我")
        
    }
   
    func addChildViewController( vc : UIViewController,imageName : String,title : String){
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        
        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
        
    }
}

extension YRMainViewController : YRTabBarDelegate{
    
    func composeButtonClick() {
    
     let nav = UINavigationController(rootViewController: YRComposeController())
        
        presentViewController(nav, animated: true, completion: nil)
        
        
    }
}
